from sqlalchemy import func

from exts import db
from sqlalchemy.dialects.mysql import LONGTEXT


# orm模型
class Base(object):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    create_time = db.Column(db.DateTime, server_default=func.now())
    update_time = db.Column(db.DateTime, server_default=func.now(), onupdate=func.now())
    states = db.Column(db.Integer, default=0)
    extends = db.Column(db.Text, default="{}")


class Pages(db.Model, Base):
    __tablename__ = "pages"
    url = db.Column(db.Text)
    page = db.Column(LONGTEXT)
    page_type = db.Column(db.Integer, default=0)


class Commodity(db.Model, Base):
    __tablename__ = "commodity"
    name = db.Column(db.String(60))
    price = db.Column(db.Integer)  # 单位：分
    sales_volume = db.Column(db.Integer)  # 单位：月销


class User(db.Model, Base):
    __tablename__ = "user"
    username = db.Column(db.String(20))
    password = db.Column(db.String(20))
